package com.changgou.business.listener;


import okhttp3.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;

import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class AdListener {

    @RabbitListener(queues = "ad_update_queue")
    public void receiveMessage(String message) {
        System.out.println ("输出message" + message);
        //远程调用
        OkHttpClient okHttpClient = new OkHttpClient ();
        String url = "http://192.168.200.128/ad_update?position=" + message;
        Request build = new Request.Builder ().url (url).build ();

        Call call = okHttpClient.newCall (build);
        call.enqueue (new Callback () {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace ();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                System.out.println ("请求成功:" + response.message ());
            }
        });

    }


}
